home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / stl / limits < prev    next >
Encoding:
Text File  |  2000-06-08  |  20.2 KB  |  538 lines

  1. /*
  2.  * Copyright (c) 1997
  3.  * Silicon Graphics Computer Systems, Inc.
  4.  *
  5.  * Permission to use, copy, modify, distribute and sell this software
  6.  * and its documentation for any purpose is hereby granted without fee,
  7.  * provided that the above copyright notice appear in all copies and
  8.  * that both that copyright notice and this permission notice appear
  9.  * in supporting documentation.  Silicon Graphics makes no
  10.  * representations about the suitability of this software for any
  11.  * purpose.  It is provided "as is" without express or implied warranty.
  12.  */
  13.  
  14. /* NOTE: This is not portable code.  Parts of numeric_limits<> are
  15.  * inherently machine-dependent.  At present this file is suitable
  16.  * for the MIPS and ia32 architectures.
  17.  */
  18.  
  19. #ifndef __SGI_CPP_LIMITS
  20. #define __SGI_CPP_LIMITS
  21.  
  22. #include <limits.h>
  23. #include <float.h>
  24. #include <stl_config.h>
  25.  
  26. __STL_BEGIN_NAMESPACE
  27.  
  28. enum float_round_style {
  29.   round_indeterminate       = -1,
  30.   round_toward_zero         =  0,
  31.   round_to_nearest          =  1,
  32.   round_toward_infinity     =  2,
  33.   round_toward_neg_infinity =  3
  34. };
  35.  
  36. enum float_denorm_style {
  37.   denorm_indeterminate = -1,
  38.   denorm_absent        =  0,
  39.   denorm_present       =  1
  40. };
  41.  
  42. // The C++ standard (section 18.2.1) requires that some of the members of
  43. // numeric_limits be static const data members that are given constant-
  44. // initializers within the class declaration.  On compilers where the
  45. // __STL_STATIC_CONST_INIT_BUG macro is defined, it is impossible to write
  46. // a standard-conforming numeric_limits class.
  47. //
  48. // There are two possible workarounds: either initialize the data
  49. // members outside the class, or change them from data members to
  50. // enums.  Neither workaround is satisfactory: the former makes it
  51. // impossible to use the data members in constant-expressions, and the
  52. // latter means they have the wrong type and that it is impossible to
  53. // take their addresses.  We choose the former workaround.
  54.  
  55. #ifdef __STL_STATIC_CONST_INIT_BUG
  56. # define __STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
  57.   enum { __mem_name = __mem_value }
  58. #else /* __STL_STATIC_CONST_INIT_BUG */
  59. # define __STL_DECLARE_LIMITS_MEMBER(__mem_type, __mem_name, __mem_value) \
  60.   static const __mem_type __mem_name = __mem_value
  61. #endif /* __STL_STATIC_CONST_INIT_BUG */
  62.  
  63. // Base class for all specializations of numeric_limits.
  64.  
  65. template <class __number>
  66. class _Numeric_limits_base {
  67. public:
  68.   __STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, false);
  69.  
  70.   static __number min() __STL_NOTHROW { return __number(); }
  71.   static __number max() __STL_NOTHROW { return __number(); }
  72.  
  73.   __STL_DECLARE_LIMITS_MEMBER(int, digits,   0);
  74.   __STL_DECLARE_LIMITS_MEMBER(int, digits10, 0);
  75.  
  76.   __STL_DECLARE_LIMITS_MEMBER(bool, is_signed,  false);
  77.   __STL_DECLARE_LIMITS_MEMBER(bool, is_integer, false);
  78.   __STL_DECLARE_LIMITS_MEMBER(bool, is_exact,   false);
  79.  
  80.   __STL_DECLARE_LIMITS_MEMBER(int, radix, 0);
  81.  
  82.   static __number epsilon() __STL_NOTHROW     { return __number(); }
  83.   static __number round_error() __STL_NOTHROW { return __number(); }
  84.  
  85.   __STL_DECLARE_LIMITS_MEMBER(int, min_exponent,   0);
  86.   __STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, 0);
  87.   __STL_DECLARE_LIMITS_MEMBER(int, max_exponent,   0);
  88.   __STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, 0);
  89.  
  90.   __STL_DECLARE_LIMITS_MEMBER(bool, has_infinity,      false);
  91.   __STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN,     false);
  92.   __STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, false);
  93.   __STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
  94.                               has_denorm,
  95.                               denorm_absent);
  96.   __STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss,   false);
  97.  
  98.   static __number infinity() __STL_NOTHROW      { return __number(); }
  99.   static __number quiet_NaN() __STL_NOTHROW     { return __number(); }
  100.   static __number signaling_NaN() __STL_NOTHROW { return __number(); }
  101.   static __number denorm_min() __STL_NOTHROW    { return __number(); }
  102.  
  103.   __STL_DECLARE_LIMITS_MEMBER(bool, is_iec559,  false);
  104.   __STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, false);
  105.   __STL_DECLARE_LIMITS_MEMBER(bool, is_modulo,  false);
  106.  
  107.   __STL_DECLARE_LIMITS_MEMBER(bool, traps,            false);
  108.   __STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before,  false);
  109.   __STL_DECLARE_LIMITS_MEMBER(float_round_style,
  110.                               round_style,
  111.                               round_toward_zero);
  112. };
  113.  
  114. #ifdef __STL_STATIC_CONST_INIT_BUG
  115. # define __STL_DEFINE_NUMERIC_BASE_MEMBER(__type, __mem)
  116. #else /* __STL_STATIC_CONST_INIT_BUG */
  117. # define __STL_DEFINE_NUMERIC_BASE_MEMBER(__type, __mem) \
  118.   template <class __number>                              \
  119.   const __type _Numeric_limits_base<__number>:: __mem
  120. #endif /* __STL_STATIC_CONST_INIT_BUG */
  121.  
  122. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_specialized);
  123. __STL_DEFINE_NUMERIC_BASE_MEMBER(int, digits);
  124. __STL_DEFINE_NUMERIC_BASE_MEMBER(int, digits10);
  125. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_signed);
  126. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_integer);
  127. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_exact);
  128. __STL_DEFINE_NUMERIC_BASE_MEMBER(int, radix);
  129. __STL_DEFINE_NUMERIC_BASE_MEMBER(int, min_exponent);
  130. __STL_DEFINE_NUMERIC_BASE_MEMBER(int, max_exponent);
  131. __STL_DEFINE_NUMERIC_BASE_MEMBER(int, min_exponent10);
  132. __STL_DEFINE_NUMERIC_BASE_MEMBER(int, max_exponent10);
  133. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, has_infinity);
  134. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, has_quiet_NaN);
  135. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, has_signaling_NaN);
  136. __STL_DEFINE_NUMERIC_BASE_MEMBER(float_denorm_style, has_denorm);
  137. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, has_denorm_loss);
  138. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_iec559);
  139. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_bounded);
  140. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, is_modulo);
  141. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, traps);
  142. __STL_DEFINE_NUMERIC_BASE_MEMBER(bool, tinyness_before);
  143. __STL_DEFINE_NUMERIC_BASE_MEMBER(float_round_style, round_style);
  144.  
  145.  
  146. // Base class for integers.
  147.  
  148. template <class _Int,
  149.           _Int __imin, _Int __imax,
  150.           int __idigits = -1, bool __ismod = true>
  151. class _Integer_limits : public _Numeric_limits_base<_Int> 
  152. {
  153. public:
  154.   __STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
  155.  
  156.   static _Int min() __STL_NOTHROW { return __imin; }
  157.   static _Int max() __STL_NOTHROW { return __imax; }
  158.  
  159.   __STL_DECLARE_LIMITS_MEMBER(int,
  160.                               digits,
  161.                               (__idigits < 0) ? (int)(sizeof(_Int) * CHAR_BIT)
  162.                                                    - (__imin == 0 ? 0 : 1) 
  163.                                               : __idigits);
  164.   __STL_DECLARE_LIMITS_MEMBER(int, digits10, (digits * 301) / 1000); 
  165.                                 // log 2 = 0.301029995664...
  166.  
  167.   __STL_DECLARE_LIMITS_MEMBER(bool, is_signed,  __imin != 0);
  168.   __STL_DECLARE_LIMITS_MEMBER(bool, is_integer, true);
  169.   __STL_DECLARE_LIMITS_MEMBER(bool, is_exact,   true);
  170.   __STL_DECLARE_LIMITS_MEMBER(int,  radix,      2);
  171.  
  172.   __STL_DECLARE_LIMITS_MEMBER(bool, is_bounded, true);
  173.   __STL_DECLARE_LIMITS_MEMBER(bool, is_modulo, __ismod);
  174. };
  175.  
  176. #ifdef __STL_STATIC_CONST_INIT_BUG
  177. # define __STL_DEFINE_INTEGER_LIMITS_MEMBER(__type, __mem)
  178. #else /* __STL_STATIC_CONST_INIT_BUG */
  179. # define __STL_DEFINE_INTEGER_LIMITS_MEMBER(__type, __mem)              \
  180.   template <class _Int, _Int __imin, _Int __imax, int __idig, bool __ismod>  \
  181.   const __type _Integer_limits<_Int, __imin, __imax, __idig, __ismod>::__mem
  182. #endif /* __STL_STATIC_CONST_INIT_BUG */
  183.  
  184. __STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_specialized);
  185. __STL_DEFINE_INTEGER_LIMITS_MEMBER(int, digits);
  186. __STL_DEFINE_INTEGER_LIMITS_MEMBER(int, digits10);
  187. __STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_signed);
  188. __STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_integer);
  189. __STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_exact);
  190. __STL_DEFINE_INTEGER_LIMITS_MEMBER(int, radix);
  191. __STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_bounded);
  192. __STL_DEFINE_INTEGER_LIMITS_MEMBER(bool, is_modulo);
  193.  
  194.  
  195. // Base class for floating-point numbers.
  196. template <class __number,
  197.          int __Digits, int __Digits10,
  198.          int __MinExp, int __MaxExp,
  199.          int __MinExp10, int __MaxExp10,
  200.          bool __IsIEC559,
  201.          float_round_style __RoundStyle>
  202. class _Floating_limits : public _Numeric_limits_base<__number>
  203. {
  204. public:
  205.   __STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true);
  206.  
  207.   __STL_DECLARE_LIMITS_MEMBER(int, digits,   __Digits);
  208.   __STL_DECLARE_LIMITS_MEMBER(int, digits10, __Digits10);
  209.  
  210.   __STL_DECLARE_LIMITS_MEMBER(bool, is_signed, true);
  211.  
  212.   __STL_DECLARE_LIMITS_MEMBER(int, radix, 2);
  213.  
  214.   __STL_DECLARE_LIMITS_MEMBER(int, min_exponent,   __MinExp);
  215.   __STL_DECLARE_LIMITS_MEMBER(int, max_exponent,   __MaxExp);
  216.   __STL_DECLARE_LIMITS_MEMBER(int, min_exponent10, __MinExp10);
  217.   __STL_DECLARE_LIMITS_MEMBER(int, max_exponent10, __MaxExp10);
  218.  
  219.   __STL_DECLARE_LIMITS_MEMBER(bool, has_infinity,      true);
  220.   __STL_DECLARE_LIMITS_MEMBER(bool, has_quiet_NaN,     true);
  221.   __STL_DECLARE_LIMITS_MEMBER(bool, has_signaling_NaN, true);
  222.   __STL_DECLARE_LIMITS_MEMBER(float_denorm_style,
  223.                               has_denorm,
  224.                               denorm_indeterminate);
  225.   __STL_DECLARE_LIMITS_MEMBER(bool, has_denorm_loss,   false);
  226.  
  227.   __STL_DECLARE_LIMITS_MEMBER(bool, is_iec559,       __IsIEC559);
  228.   __STL_DECLARE_LIMITS_MEMBER(bool, is_bounded,      true);
  229.   __STL_DECLARE_LIMITS_MEMBER(bool, traps,           true);
  230.   __STL_DECLARE_LIMITS_MEMBER(bool, tinyness_before, false);
  231.  
  232.   __STL_DECLARE_LIMITS_MEMBER(float_round_style, round_style, __RoundStyle);
  233. };
  234.  
  235. #ifdef __STL_STATIC_CONST_INIT_BUG
  236. # define __STL_DEFINE_FLOAT_LIMITS_MEMBER(__type, __mem)
  237. #else /* __STL_STATIC_CONST_INIT_BUG */
  238. # define __STL_DEFINE_FLOAT_LIMITS_MEMBER(__type, __mem)                   \
  239.   template <class __Num, int __Dig, int __Dig10,                           \
  240.             int __MnX, int __MxX, int __MnX10, int __MxX10,                \
  241.             bool __IsIEEE, float_round_style __Sty>                        \
  242.   const __type _Floating_limits<__Num, __Dig, __Dig10,                     \
  243.                                 __MnX, __MxX, __MnX10, __MxX10,            \
  244.                                 __IsIEEE, __Sty>:: __mem
  245. #endif /* __STL_STATIC_CONST_INIT_BUG */
  246.  
  247. __STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, is_specialized);  
  248. __STL_DEFINE_FLOAT_LIMITS_MEMBER(int, digits);  
  249. __STL_DEFINE_FLOAT_LIMITS_MEMBER(int, digits10);  
  250. __STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, is_signed);  
  251. __STL_DEFINE_FLOAT_LIMITS_MEMBER(int, radix);  
  252. __STL_DEFINE_FLOAT_LIMITS_MEMBER(int, min_exponent);  
  253. __STL_DEFINE_FLOAT_LIMITS_MEMBER(int, max_exponent);  
  254. __STL_DEFINE_FLOAT_LIMITS_MEMBER(int, min_exponent10);  
  255. __STL_DEFINE_FLOAT_LIMITS_MEMBER(int, max_exponent10);  
  256. __STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, has_infinity);
  257. __STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, has_quiet_NaN);
  258. __STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, has_signaling_NaN);
  259. __STL_DEFINE_FLOAT_LIMITS_MEMBER(float_denorm_style, has_denorm);
  260. __STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, has_denorm_loss);
  261. __STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, is_iec559);
  262. __STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, is_bounded);
  263. __STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, traps);
  264. __STL_DEFINE_FLOAT_LIMITS_MEMBER(bool, tinyness_before);
  265. __STL_DEFINE_FLOAT_LIMITS_MEMBER(float_round_style, round_style);
  266.  
  267.  
  268. #undef __STL_DECLARE_NUMERIC_LIMITS_MEMBER
  269. #undef __STL_DEFINE_NUMERIC_BASE_MEMBER
  270. #undef __STL_DEFINE_INTEGER_LIMITS_MEMBER
  271. #undef __STL_DEFINE_FLOAT_LIMITS_MEMBER
  272.  
  273. // Class numeric_limits
  274.  
  275. // The unspecialized class.
  276.  
  277. template<class _Tp> 
  278. class numeric_limits : public _Numeric_limits_base<_Tp> {};
  279.  
  280. // Specializations for all built-in integral types.
  281.  
  282. #ifndef __STL_NO_BOOL
  283.  
  284. __STL_TEMPLATE_NULL
  285. class numeric_limits<bool>
  286.   : public _Integer_limits<bool, false, true, 1, false>
  287. {};
  288.  
  289. #endif /* __STL_NO_BOOL */
  290.  
  291. __STL_TEMPLATE_NULL
  292. class numeric_limits<char>
  293.   : public _Integer_limits<char, CHAR_MIN, CHAR_MAX>
  294. {};
  295.  
  296. __STL_TEMPLATE_NULL
  297. class numeric_limits<signed char>
  298.   : public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX>
  299. {};
  300.  
  301. __STL_TEMPLATE_NULL
  302. class numeric_limits<unsigned char>
  303.   : public _Integer_limits<unsigned char, 0, UCHAR_MAX>
  304. {};
  305.  
  306. #ifdef __STL_HAS_WCHAR_T
  307.  
  308. __STL_TEMPLATE_NULL
  309. class numeric_limits<wchar_t>
  310.   : public _Integer_limits<wchar_t, INT_MIN, INT_MAX>
  311. {};
  312.  
  313. #endif
  314.  
  315. __STL_TEMPLATE_NULL
  316. class numeric_limits<short>
  317.   : public _Integer_limits<short, SHRT_MIN, SHRT_MAX>
  318. {};
  319.  
  320. __STL_TEMPLATE_NULL
  321. class numeric_limits<unsigned short>
  322.   : public _Integer_limits<unsigned short, 0, USHRT_MAX>
  323. {};
  324.  
  325. __STL_TEMPLATE_NULL
  326. class numeric_limits<int>
  327.   : public _Integer_limits<int, INT_MIN, INT_MAX>
  328. {};
  329.  
  330. __STL_TEMPLATE_NULL
  331. class numeric_limits<unsigned int>
  332.   : public _Integer_limits<unsigned int, 0, UINT_MAX>
  333. {};
  334.  
  335. __STL_TEMPLATE_NULL
  336. class numeric_limits<long>
  337.   : public _Integer_limits<long, LONG_MIN, LONG_MAX>
  338. {};
  339.  
  340. __STL_TEMPLATE_NULL
  341. class numeric_limits<unsigned long>
  342.   : public _Integer_limits<unsigned long, 0, ULONG_MAX>
  343. {};
  344.  
  345. #ifdef __STL_LONG_LONG
  346.  
  347. // Some compilers have long long, but don't define the
  348. // LONGLONG_MIN and LONGLONG_MAX macros in limits.h.  This
  349. // assumes that long long is 64 bits.
  350. #if !defined(LONGLONG_MIN) && !defined(LONGLONG_MAX) \
  351.                            && !defined(ULONGLONG_MAX)
  352.  
  353. #define ULONGLONG_MAX 0xffffffffffffffffLLU
  354. #define LONGLONG_MAX 0x7fffffffffffffffLL
  355. #define LONGLONG_MIN (-LONGLONG_MAX - 1LL)
  356.  
  357. #endif
  358.  
  359. __STL_TEMPLATE_NULL
  360. class numeric_limits<long long>
  361.   : public _Integer_limits<long long, LONGLONG_MIN, LONGLONG_MAX>
  362. {};
  363.  
  364. __STL_TEMPLATE_NULL
  365. class numeric_limits<unsigned long long>
  366.   : public _Integer_limits<unsigned long long, 0, ULONGLONG_MAX>
  367. {};
  368.  
  369. #endif /* __STL_LONG_LONG */
  370.  
  371. // Specializations for all built-in floating-point type.
  372.  
  373. __STL_TEMPLATE_NULL class numeric_limits<float>
  374.   : public _Floating_limits<float, 
  375.                             FLT_MANT_DIG,   // Binary digits of precision
  376.                             FLT_DIG,        // Decimal digits of precision
  377.                             FLT_MIN_EXP,    // Minimum exponent
  378.                             FLT_MAX_EXP,    // Maximum exponent
  379.                             FLT_MIN_10_EXP, // Minimum base 10 exponent
  380.                             FLT_MAX_10_EXP, // Maximum base 10 exponent
  381.                             true,           // conforms to iec559
  382.                             round_to_nearest>
  383. {
  384. public:
  385.   static float min() __STL_NOTHROW { return FLT_MIN; }
  386.   static float denorm_min() __STL_NOTHROW { return FLT_MIN; }
  387.   static float max() __STL_NOTHROW { return FLT_MAX; }
  388.   static float epsilon() __STL_NOTHROW { return FLT_EPSILON; }
  389.   static float round_error() __STL_NOTHROW { return 0.5f; } // Units: ulps.
  390.   static float infinity() __STL_NOTHROW;
  391.   static float quiet_NaN() __STL_NOTHROW;
  392.   static float signaling_NaN() __STL_NOTHROW;
  393. };
  394.  
  395. __STL_TEMPLATE_NULL class numeric_limits<double>
  396.   : public _Floating_limits<double, 
  397.                             DBL_MANT_DIG,   // Binary digits of precision
  398.                             DBL_DIG,        // Decimal digits of precision
  399.                             DBL_MIN_EXP,    // Minimum exponent
  400.                             DBL_MAX_EXP,    // Maximum exponent
  401.                             DBL_MIN_10_EXP, // Minimum base 10 exponent
  402.                             DBL_MAX_10_EXP, // Maximum base 10 exponent
  403.                             true,           // conforms to iec559
  404.                             round_to_nearest>
  405. {
  406. public:
  407.   static double min() __STL_NOTHROW { return DBL_MIN; }
  408.   static double denorm_min() __STL_NOTHROW { return DBL_MIN; }
  409.   static double max() __STL_NOTHROW { return DBL_MAX; }
  410.   static double epsilon() __STL_NOTHROW { return DBL_EPSILON; }
  411.   static double round_error() __STL_NOTHROW { return 0.5; } // Units: ulps.
  412.   static double infinity() __STL_NOTHROW;
  413.   static double quiet_NaN() __STL_NOTHROW;
  414.   static double signaling_NaN() __STL_NOTHROW;
  415. };
  416.  
  417. __STL_TEMPLATE_NULL class numeric_limits<long double>
  418.   : public _Floating_limits<long double, 
  419.                             LDBL_MANT_DIG,  // Binary digits of precision
  420.                             LDBL_DIG,       // Decimal digits of precision
  421.                             LDBL_MIN_EXP,   // Minimum exponent
  422.                             LDBL_MAX_EXP,   // Maximum exponent
  423.                             LDBL_MIN_10_EXP,// Minimum base 10 exponent
  424.                             LDBL_MAX_10_EXP,// Maximum base 10 exponent
  425.                             false,          // Doesn't conform to iec559
  426.                             round_to_nearest>
  427. {
  428. public:
  429.   static long double min() __STL_NOTHROW { return LDBL_MIN; }
  430.   static long double denorm_min() __STL_NOTHROW { return LDBL_MIN; }
  431.   static long double max() __STL_NOTHROW { return LDBL_MAX; }
  432.   static long double epsilon() __STL_NOTHROW { return LDBL_EPSILON; }
  433.   static long double round_error() __STL_NOTHROW { return 4; } // Units: ulps.
  434.   static long double infinity() __STL_NOTHROW;
  435.   static long double quiet_NaN() __STL_NOTHROW;
  436.   static long double signaling_NaN() __STL_NOTHROW;
  437. };
  438.  
  439. // We write special values (Inf and NaN) as bit patterns and 
  440. // cast the the appropriate floating-point types. 
  441.  
  442. #if defined(_MIPSEB)
  443. // Big-endian MIPS.  float is 32 bits, double 64, long double 128.
  444.  
  445. #define _Define_float(__f, __h, __l)                                     \
  446.    inline float numeric_limits<float>::__f() __STL_NOTHROW {             \
  447.      static const unsigned short __x[2] = { __h, __l };                  \
  448.      return *reinterpret_cast<const float*>(__x); }
  449. #define _Define_double(__f, __h, __l)                                    \
  450.    inline double numeric_limits<double>::__f() __STL_NOTHROW {           \
  451.      static const unsigned short __x[4] = { __h, __l };                  \
  452.      return *reinterpret_cast<const double*>(__x); }
  453. #define _Define_ldouble(__f, __h, __l)                                   \
  454.    inline long double numeric_limits<long double>::__f() __STL_NOTHROW { \
  455.      static const unsigned short __x[8] = { __h, __l };                  \
  456.      return *reinterpret_cast<const long double*>(__x); }
  457.  
  458. _Define_float(infinity, 0x7f80, 0)
  459. _Define_float(quiet_NaN, 0x7f81, 0)
  460. _Define_float(signaling_NaN, 0x7fc1, 0)
  461.  
  462. _Define_double(infinity, 0x7ff0, 0)
  463. _Define_double(quiet_NaN, 0x7ff1, 0)
  464. _Define_double(signaling_NaN, 0x7ff9, 0)
  465.  
  466. _Define_ldouble(infinity, 0x7ff0, 0)
  467. _Define_ldouble(quiet_NaN, 0x7ff1, 0)
  468. _Define_ldouble(signaling_NaN, 0x7ff9, 0)
  469.  
  470. #elif defined(__i386) || defined(_M_IX86)
  471. // Little-endian ia32.  float is 32 bits, double 64, long double 80.
  472.  
  473. #define _Define_float(__f, __h, __l)                                     \
  474.    inline float numeric_limits<float>::__f() __STL_NOTHROW {             \
  475.      static const unsigned short __x[2] = { __l, __h };                  \
  476.      return *reinterpret_cast<const float*>(__x); }
  477. #define _Define_double(__f, __h, __l)                                    \
  478.    inline double numeric_limits<double>::__f() __STL_NOTHROW {           \
  479.      static const unsigned short __x[4] = { 0, 0, __l, __h };            \
  480.      return *reinterpret_cast<const double*>(__x); }
  481. #define _Define_ldouble(__f, __h, __l)                                   \
  482.    inline long double numeric_limits<long double>::__f() __STL_NOTHROW { \
  483.      static const unsigned short __x[5] = { 0, 0, 0, __l, __h };         \
  484.      return *reinterpret_cast<const long double*>(__x); }
  485.  
  486. _Define_float(infinity, 0x7f80, 0)
  487. _Define_float(quiet_NaN, 0x7fa0, 0)
  488. _Define_float(signaling_NaN, 0x7fc0, 0)
  489.  
  490. _Define_double(infinity, 0x7ff0, 0)
  491. _Define_double(quiet_NaN, 0x7ff4, 0)
  492. _Define_double(signaling_NaN, 0x7ff8, 0)
  493.  
  494. _Define_ldouble(infinity, 0x7fff, 0x8000)
  495. _Define_ldouble(quiet_NaN, 0x7fff, 0xa000)
  496. _Define_ldouble(signaling_NaN, 0x7fff, 0xc000)
  497.  
  498. #else 
  499.  
  500. /* This is an architecture we don't know how to handle.  Return some 
  501.    obviously wrong values. */
  502.  
  503. #define _Define_float(__f)                                               \
  504.    inline float numeric_limits<float>::__f() __STL_NOTHROW {             \
  505.      return 0; }
  506. #define _Define_double(__f)                                              \
  507.    inline double numeric_limits<double>::__f() __STL_NOTHROW {           \
  508.      return 0; }
  509. #define _Define_ldouble(__f)                                             \
  510.    inline long double numeric_limits<long double>::__f() __STL_NOTHROW { \
  511.      return 0; }
  512.  
  513. _Define_float(infinity)
  514. _Define_float(quiet_NaN)
  515. _Define_float(signaling_NaN)
  516.  
  517. _Define_double(infinity)
  518. _Define_double(quiet_NaN)
  519. _Define_double(signaling_NaN)
  520.  
  521. _Define_ldouble(infinity)
  522. _Define_ldouble(quiet_NaN)
  523. _Define_ldouble(signaling_NaN)   
  524.  
  525. #endif
  526.  
  527. #undef _Define_float
  528. #undef _Define_double
  529. #undef _Define_ldouble
  530.  
  531. __STL_END_NAMESPACE
  532.  
  533. #endif /* __SGI_CPP_LIMITS */
  534.  
  535. // Local Variables:
  536. // mode:C++
  537. // End:
  538.